# decorator add
# 装饰器只能带一个参数
def logging(flag):

    def decorator(mufunc):

        def fun_in(a, b):

            if flag == '+':
                print('正在加法计算')
            elif flag =='-':
                print('正在减法计算')

            c = mufunc(a, b)
            return c

        # 有返回
        return fun_in

    return decorator

# @logging('+')     #  add =  decorator(add)
# def add(a, b):
#     c = a + b
#     return c
#
# @logging('-')     #  add =  decorator(add)
# def sub(a, b):
#     c = a - b
#     return c


def add(a, b):
    c = a + b
    return c

# 纯手工的方式进行装饰
decorator = logging('+')
add = decorator(add)

result = add(10, 20)
print(result)
# result = sub(10, 20)
# print(result)